<template>
<a-spin :spinning="spinning">
      <van-nav-bar
        title="完工入库审批"
    />
    <div class="layout">
        <van-form >
            <div class="title">
                <h3>单据信息</h3>
            </div>
            <van-cell-group inset>
                <van-field
                v-model="variables.reportWorkNo"
                name="完工单号"
                label="完工单号"
                />
                <van-field
                v-model="variables.postDate"
                name="事务处理日期"
                label="事务处理日期"
                />
                <van-field
                v-model="variables.productionProcessesName"
                name="工序"
                label="工序"
                />
                <van-field
                v-model="variables.workCenterName"
                name="工作中心"
                label="工作中心"
                />
                <van-field
                v-model="variables.teamShiftName"
                name="班次"
                label="班次"
                />
                <van-field
                v-model="variables.teamGroupName"
                name="班组"
                label="班组"
                />
                 <van-field
                v-model="variables.workDate"
                name="任务日期"
                label="任务日期"
                />
                <van-field
                v-model="variables.executor"
                name="操作人"
                label="操作人"
                />
            </van-cell-group>
             <div class="title">
                <h3>完工信息</h3>
            </div>
            <!-- //折叠面板 -->
            <van-collapse v-model="activeNames">
                <van-collapse-item
                 v-for="(item,index) in variables.yhReportWorkDetailList"
                 :key="index"
                 :title="item.materialName"
                 :name="index+1"
                >
                    <van-cell-group inset>
                        <div style="display:flex;">
                             <van-field
                            v-model="item.batchNo"
                            name="批次号"
                            label="批次号"
                            >
                             <template #input>
                                    <a @click="seeBatchNo(item.batchNo)" v-if="item.batchNo">查看</a>
                                    <span v-if="!item.batchNo">查看</span>
                                </template>
                            </van-field>
                            <van-field
                            v-model="item.h2oCount"
                            name="水分"
                            label="水分"
                            />
                        </div>
                        <div style="display:flex;">
                        <van-field
                            v-model="item.finishedCount"
                            name="数量"
                            label="数量"
                        />
                            <van-field
                            name="质检数据"
                            label="质检数据"
                            >
                                <template #input>
                                    <a @click="seeQuantity(item.qualityCode)" v-if="item.qualityCode">查看</a>
                                    <span v-if="!item.qualityCode">查看</span>
                                </template>
                            </van-field>
                        </div>
                    </van-cell-group>
                </van-collapse-item>
            </van-collapse>
            <div style="margin: 0.667rem;display:flex">
                <van-button round block type="primary" native-type="submit" style="width:4.167rem" @click="deal(2)">
                同意
                </van-button>
                <van-button round block loading-text="审批中..." type="primary" native-type="submit" style="width:4.167rem" @click="deal(3)">
                驳回
                </van-button>
            </div>
        </van-form>
    </div>
</a-spin>
</template>
<script lang="ts">
import { defineComponent,ref ,reactive} from 'vue';
import { get,post ,getQueryVariable} from "@/request/useRequest";
import options from "@/views/workflowConfig/yuanfucaishouhuoConfig";
import { workflow } from "@/utils/hooks/workflow";
import { Props } from '@/components/typing';
export default defineComponent({
  name: 'wangongshenpi',
  setup(){
    let variables:any=ref({})//传参用
    let data:any=ref([])//h5展示用
    let id=getQueryVariable("id")
    let formInfoId=getQueryVariable("formInfoId")
    debugger
    const activeNames:any = ref([]);
    get('formInstance/getFormData',{id,formInfoId}).then((res:any)=>{
        if(res.status==200){
            activeNames.value=[]
            variables.value=res.data.formData.variable.variables
            variables.value.yhReportWorkDetailList?.forEach((item:any,index:number)=>{
                activeNames.value.push(index+1)
                post("yhReportWork/getReportQCData",[{
                    materialCode:item.materialCode,
                    batchNo:item.batchNo
                }]).then((res:any)=>{
                    if(res.status==200){
                        item.qualityCode=res.data[0].qualityCode
                        item.h2oCount=res.data[0].h2oCount
                    }
                })
            })
        } 
    })
    const seeQuantity=(qualityCode:string)=>{

    }
    const seeBatchNo=(batchNo:string)=>{

    }
    const {
      keyConfig,
      state,
      start,
      save,
      deal,
      fallback,
      diagram,
      execute,
      refreshDeal,
      assignKey,
      formKey,
      spinning,
      delayTime,
      title,
    } = workflow(variables,options,true);

    return{
      variables,
      activeNames,
      deal,
      data,
      spinning,
      seeQuantity,
      seeBatchNo
    }
  }
});
</script>
<style lang="less">
.title{
    background-color: aqua;
    text-align: center
}
</style>